<?php
namespace app\Capital\model;
use think\Model;
use think\Db;
class capital extends Model {
    //保存订单
        public function allsave($data,$notype,$type='S'){
            switch($type){
                case 'S':
                    $key1='shopid';
                    $key2='shopname';
                    $member=$data['shopid'][0];
                    break;
                case 'M':
                    $key1='memberid';
                    $key2='member_name';
                    $member=$data['memberid'][0];
                    break;
                default:
                    $member="";
                    break;
            }
            if($member){
                $memberArr=explode('-',$member);
                $data[$key1]=$memberArr[0];
                $data[$key2]=$memberArr[1];
                $No = date('YmdHis');
                $data['createtime'] = time();
                $data['no'] = $type.$notype . $data[$key1] . $No;
            }else{
                $data="";
            }
            return $data;
        }


    //获取单据原因
    public static function get_type($type=""){
        $data=Db::name("item_type")->where("type=$type")->select();
        $result=[];
        foreach ($data  as $value){
            $result[$value['id']]=$value['name'];
        }
        return $result;
    }

    //获取会员信息
    public static function get_member($id){
        $data=Db::name("member")->where("id=$id")->find();
        $data['creditlimit']=getPrice($data['creditlimit']);
        $data['temporary_creditlimit']=getPrice($data['temporary_creditlimit']);
        $data['temporary_time']=$data['temporary_time']?date('Y-m-d',$data['temporary_time']):'';
        $data['temporary_endtime']=$data['temporary_endtime']?date('Y-m-d',$data['temporary_endtime']):'';
        $data['defalut_time']= $data['temporary_time'].','.$data['temporary_endtime'];
        return $data;
    }

}